package com.mes.cloud.controller;

import com.github.pagehelper.PageInfo;
import com.mes.cloud.dto.BmeBcAppletDTO;
import com.mes.cloud.service.BmeBcAppletService;
import com.mes.cloud.util.CommPager;
import com.mes.cloud.util.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
* 视图项配置
* @author wxm
* @Time 2019-6-26
*/
@Api(tags = "BmeBcAppletController", description = "BcApplet配置")
@RestController
@RequestMapping("/bmeBcApplet")
public class BmeBcAppletController {
    private static final Logger LOGGER = LoggerFactory.getLogger(BmeBcAppletController.class);

    @Autowired
    private BmeBcAppletService bmeBcAppletService;

    @ApiOperation(value = "列表 无分页")
    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    public JSONResult getList(@RequestBody Map<Object, Object> map) {
        JSONResult result = JSONResult.success("", 200, "");
        return result;
    }

    @ApiOperation(value = "列表 分页 ")
    @RequestMapping(value = "/getPageList", method = RequestMethod.POST)
    public JSONResult getPageList(@RequestBody Map<Object, Object> map) {
        JSONResult jsonResult = null;
        try {
            CommPager<BmeBcAppletDTO> pageInfo = bmeBcAppletService.getPageList(map);
            jsonResult = JSONResult.success(pageInfo);
        } catch (Exception e) {
            LOGGER.error("Class BcViewController :Method findPageList:OutParam E: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        return jsonResult;
    }

    @ApiOperation(value = "获取记录数")
    @RequestMapping(value = "/getCount", method = RequestMethod.POST)
    public JSONResult getCount(@RequestBody Map<Object, Object> map) {
        JSONResult result = JSONResult.success("", 200, "");
        return result;
    }

    @ApiOperation(value = "新增")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JSONResult insert() {
        JSONResult result = JSONResult.success("", 200, "");
        return result;
    }

    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JSONResult update(@RequestBody BmeBcAppletDTO bmeBcAppletDTO) {
        JSONResult jsonResult = null;
        try {
            bmeBcAppletService.update(bmeBcAppletDTO);
            jsonResult = JSONResult.success();
        }catch (Exception e){
            LOGGER.error("Class BmeBcAppletController:Method update:OutParam E: "+e.getMessage());
            jsonResult = JSONResult.fail(201,e.getMessage());
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JSONResult delete() {
        JSONResult result = JSONResult.success("", 200, "");
        return result;
    }

    @ApiOperation(value = "详情")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public JSONResult get() {
        JSONResult result = JSONResult.success("", 200, "");
        return result;
    }
}
